package com.yipao.db.service.devinfo;

import com.yipao.db.dao.dev.DevMaterialSlotMapper;
import com.yipao.db.domain.devinfo.DevMaterialSlot;
import com.yipao.db.domain.devinfo.vo.DevMaterialSlotResp;
import com.yipao.db.util.DeleteStatusConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备原料槽位
 *
 * @author tianhao
 */
@Service
public class DevFormulaSlotService {
    @Resource
    private DevMaterialSlotMapper devFormulaSlotMapper;

    /**
     * 修改
     *
     * @param devFormulaSlot
     * @return
     */
    public int update(DevMaterialSlot devFormulaSlot) {
        return devFormulaSlotMapper.update(devFormulaSlot);
    }

    /**
     * 查询指定设备下的设备原料卡槽
     *
     * @param devCode 设备编号
     * @return
     */
    public List<DevMaterialSlotResp> queryByDevCode(Integer devCode) {
        return devFormulaSlotMapper.queryByDevCode(devCode, DeleteStatusConstant.NOT_DELETED);
    }

    /**
     * 批量更新
     *
     * @param devId
     * @param formulaId
     * @return
     */
    public Integer updates(String devId, List<String> formulaId) {
        Integer update = 0;
        List<DevMaterialSlotResp> devFormulaSlotResps = devFormulaSlotMapper.queryByDevCode(Integer.valueOf(devId), DeleteStatusConstant.NOT_DELETED);
        for (int i = 0; i < devFormulaSlotResps.size(); i++) {
            update++;
            String s = formulaId.get(i);
            DevMaterialSlotResp devFormulaSlotResp = devFormulaSlotResps.get(i);
            devFormulaSlotResp.setMaterialId(Integer.valueOf(s));
            update = devFormulaSlotMapper.update(devFormulaSlotResp);
        }

        return update;
    }


    /**
     * 删除设备原料卡槽
     *
     * @param devId 设备id
     * @return
     */
    public int deleteDevSlotByDevId(Integer devId) {
        return devFormulaSlotMapper.deleteDevSlotByDevId(devId);
    }
}
